//
//  MessageMgr.m
//  carcareIOS
//
//  Created by ileo on 15/12/11.
//  Copyright © 2015年 baozun. All rights reserved.
//

#import "MessageMgr.h"
#import "NetAdvertice.h"
#import "AdverticePageModel.h"
#import "TriggerEngine.h"

@interface MessageMgr() <TriggerVister>

@end

NSString * const Messages_Update = @"Messages_Update";

@implementation MessageMgr

IMP_SINGLETON

- (instancetype)init
{
    self = [super init];
    if (self) {
        [[TriggerEngine sharedInstance] addVisiter:self];
        [MessageMgr loadMessageSuccess:^(NSArray *datas) {
        } fail:nil];
    }
    return self;
}

#pragma mark -
-(void)triggerByAccountLogout{
}

#pragma mark -

-(void)readAll{
    [[NSNotificationCenter defaultCenter] postNotificationName:Messages_Update object:nil];
}

+(void)loadMessageSuccess:(void (^)(NSArray * datas))success fail:(void (^)())fail{
    
    [NetAdvertice loadAdverticesWithCode:APP_MESSAGE success:^(NSArray *list) {
        
//        if (maxID > [MessageMgr sharedInstance].aiLoc.lastID) {
            AdverticePageModel *model = list.firstObject;
//            [MessageMgr sharedInstance].aiLoc.lastID = maxID;
//            [MessageMgr sharedInstance].aiLoc.readAll = NO;
            [MessageMgr sharedInstance].message = model.title;
            [MessageMgr sharedInstance].nums = list.count;
            [[NSNotificationCenter defaultCenter] postNotificationName:Messages_Update object:nil];
//        }
        if(success)success(list);
    } fail:fail];
    
}


@end
